package com.nd.controller.wx;


import com.nd.pojo.bean.Order;
import com.nd.pojo.bean.OrderGoods;
import com.nd.pojo.bo.wx.OrderCommentBO;
import com.nd.pojo.bo.wx.OrderSubmitBo;
import com.nd.pojo.vo.wx.BaseRespWXVo;
import com.nd.pojo.vo.wx.OrderActionBO;
import com.nd.pojo.vo.wx.WxOrderDetailVO;
import com.nd.pojo.vo.wx.WxOrderListVO;
import com.nd.service.wx.WxOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 订单模块
 * @author: Aaron
 * @create: 2021-06-07 14:49
 **/
@RestController
@RequestMapping("wx")
public class OrderController {
    @Autowired
    WxOrderService wxOrderService;

    @RequestMapping("order/list")
    public BaseRespWXVo orderList(@RequestParam Integer showType,@RequestParam("page") Integer page,@RequestParam("size") Integer size) {
        WxOrderListVO wxOrderListVO = wxOrderService.orderList(showType,page,size);
        return BaseRespWXVo.ok(wxOrderListVO);
    }

    @RequestMapping("order/detail")
    public BaseRespWXVo orderDetail(Integer orderId) {
        WxOrderDetailVO wxOrderDetailVO = wxOrderService.orderDetail(orderId);
        return BaseRespWXVo.ok(wxOrderDetailVO);
    }

    @RequestMapping("order/cancel")
    public BaseRespWXVo orderCancel(@RequestBody OrderActionBO orderId) {
        wxOrderService.orderCancel(orderId);
        return BaseRespWXVo.ok();
    }

    @RequestMapping("order/refund")
    public BaseRespWXVo orderRefund(@RequestBody OrderActionBO orderId) {
        wxOrderService.orderWxRefund(orderId);
        return BaseRespWXVo.ok();
    }

    @RequestMapping("order/delete")
    public BaseRespWXVo orderDelete(@RequestBody OrderActionBO orderId) {
        wxOrderService.orderWxDelete(orderId);
        return BaseRespWXVo.ok();
    }

    @RequestMapping("order/confirm")
    public BaseRespWXVo orderConfirm(@RequestBody OrderActionBO orderId) {
        wxOrderService.orderWxConfirm(orderId);
        return BaseRespWXVo.ok();
    }

    @RequestMapping("order/goods")
    public BaseRespWXVo orderGoods(Integer orderId, Integer goodsId) {
        OrderGoods orderGoods = wxOrderService.orderGoods(orderId,goodsId);
        return BaseRespWXVo.ok(orderGoods);
    }

    @RequestMapping("order/comment")
    public BaseRespWXVo orderComment(@RequestBody OrderCommentBO orderCommentBO) {
        wxOrderService.orderComment(orderCommentBO);
        return BaseRespWXVo.ok();
    }

    @RequestMapping("order/submit")
    //下单
    public BaseRespWXVo orderSubmit(@RequestBody OrderSubmitBo orderSubmitBo){
        OrderGoods orderId = wxOrderService.orderSubmit(orderSubmitBo);
        if(orderId == null) return BaseRespWXVo.fail("下单异常");
        return BaseRespWXVo.ok(orderId);
    }
    @RequestMapping("order/prepay")
    //付款
    public BaseRespWXVo prepay(@RequestBody OrderGoods orderGoods){
        Integer prepay = wxOrderService.prepay(orderGoods);
        if(prepay == 10000) return BaseRespWXVo.fail("付款失败！或者已经付过款！");
        return BaseRespWXVo.fail(725,"不能付款，但是默认付款成功！");
    }
}
